package dnl.util.ui.tree;

import javax.swing.Icon;


/**
 * @author Daniel Or
 * @version 1.0
 */
public abstract class TreeItem {

  //~ Constructors =============================================================

  /**
   * Constructor for TreeItem.
   */
  public TreeItem(Object data) {
    this.data = data;
  }

  //~ Methods ==================================================================


	synchronized TreeItem[] expandImpl(){
		expansionResult = null;
    Runnable r = new Runnable() {
    	@Override
      public void run() {
      	expansionResult = TreeItem.this.expand();
      }
    };
    Thread t = new Thread(r);
    t.start();
    try {
			t.join(timeout);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		/*if(expansionResult == null && t.isAlive())
			t.stop();
			KILL KILL KILL!
			*/
    return expansionResult;		 
	}

  /**
   *
   * @return 
   */
  public abstract Icon getIcon();

  /**
   *
   * @return 
   */
  public abstract Icon getExpandedIcon();

  /**
   *
   * @return 
   */
  public abstract TreeItem[] expand();

  /**
   *
   * @return 
   */
  public abstract boolean isExpandable();

  /**
   *
   * @return 
   */
  public Object getData() {
    return data;
  }

	/**
	 * Sets the timeout used by <code>TreeItem</code>s when the expand() method is
	 * called.
	 * @param timeout timeout in seconds
	 */
	public static void setTimeout(int timeout){
		TreeItem.timeout = timeout*1000;
	}
	
  //~ Instance variables =======================================================

	private static int timeout = 2*60*1000;
  private Object data;
  private TreeItem[] expansionResult;
}
